﻿using System;
using System.Reflection;

namespace Core.Logic.Options
{
    public enum Language
    {
        [LanguageString("en-US")]
        English = 0,

        [LanguageString("ru-RU")]
        Русский
    }

    public class LanguageString : Attribute
    {
        private readonly string _value;

        public LanguageString(string value)
        {
            _value = value;
        }

        public string Value
        {
            get { return _value; }
        }
    }

    public static class LanguageStringEnumExtensions
    {
        public static string GetStringValue(this Enum value)
        {
            string output = null;
            Type type = value.GetType();

            FieldInfo fi = type.GetField(value.ToString());
            var attrs = fi.GetCustomAttributes(typeof(LanguageString), false) as LanguageString[];
            if (attrs.Length > 0)
            {
                output = attrs[0].Value;
            }

            return output;
        }
    }
}